home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: Amiga Public Domain Connection
/
APDC Disk #025 - Programming Languages (198x)(Amiga Public Domain Connection)(US)[m][WB].zip
/
APDC Disk #025 - Programming Languages (198x)(Amiga Public Domain Connection)(US)[m][WB].adf
/
Logo.Doc
< prev
next >
Wrap
Text File
|
1988-03-15
|
19KB
|
576 lines
ALOGO - © 1986 by Gerald Owens
Permission is given for free, non-commercial distribution.
This software is TRUE shareware: If you have contributed something
to the public domain, then you can keep it for free! Otherwise, it is
requested that you send a tax deductible donation of $5.00 to:
Wycliffe Associates
Box 2000
Orange, Ca. 92669-9984
Specify that the money is to go for literacy training in less
developed countries, and tell them that "S" sent you. Be sure to tell
them not to send further information if you don't want it.
Please direct all bug reports and suggestions for improvements to:
Gerald Owens Gerald Owens
C/O William Richardson C/O Amiga Atlanta
1599 Council Bluff Dr. Box 7724
Atlanta, Ga. 30345 Atlanta, Ga. 30357
LIMITATIONS
This is just the graphics portions of LOGO. I have tried to
follow the Apple II LOGO commands as closely as possible, with the
exception of file, editor, and printer related commands. Any good
book on LOGO should be of help.
PROBLEM AREAS
A single window is used for the editor, command, and graphics
window. Wierd things happen to the "turtle" when things get scrolled.
Do not panic! Repeat, do NOT panic if after successfully executing
a procedure, you re-edit the buffer and find a blank screen! The
editor is fixed to place the cursor in front of the NEXT statement
to be executed. If there is an error, the cursor will be in front
of the offending statement. When a procedure returns, the cursor
is temporarily placed after the END or the OUTPUT statement, so if
the last procedure executed was the last procedure in the editor
buffer, the cursor will be placed after the END statement, and so
may appear alone on a blank screen. Just press SHIFT-UP ARROW to
get to your code.
The editor is not very good. I hope that if a later version comes
out, it will be worthy of alternate use as a programmer's editor.
The program polls the window message port constantly for a keypress
while it executes, so that it can stop at a keypress. Unfortunately,
this takes up so much CPU time that it is virtually unable to be
multi-processed. My apologies. I'm sure there's a work-around, but
the Amiga is such a complicated machine that it will probably take a
while for me to get sophisticated enough to implement it in assembler.
There are no global variables. All procedure variables are
sort of local/global. They're global in the sense that they are
accessible outside of the procedure, and local in the sense that
when a procedure is entered, the old value is saved, and when the
procedure is exited, the old value is restored. Every unique variable
name is placed in a table and all accesses refer to that central
copy, so the scope can be classified as being dynamic. If you want
global variables, declare a dummy procedure with "local" variables
having the names of the desired global variables.
Procedures and variables are declared using the editor. They
cannot be declared from the command processor. When declaring a
procedure, the header (TO <name> <vars>) MUST START on separate lines.
HOW TO RUN
ALOGO cannot be executed from the Workbench. Rather, get into the
CLI and type in:
logo
[Note: To open the CLI, it must be turned "On" in Preferences. Then
reboot. The CLI icon will be in the System drawer of that Workbench disk.
Click on it. Enter "cd AMICUS_#18:logo" and then "logo" as above.]
GENERAL COMMANDS
These commands are in addition to the regular ALOGO commands, but
only one command can be typed in on a line.
NEW
Clear the editor buffer. Will prompt if contents have been
changed and not saved.
LOAD filename
Clears the editor buffer and loads the text file into the
editor buffer. If the previous contents of the buffer was
changed and not saved, the computer will ask if it is OK
to delete the file.
***WARNING*** Do not use a file name with an embedded blank.
Even if it has ""'s around it!
SAVE
Without a file name, saves the editor buffer with the same
name as it was previously loaded or saved under.
SAVE filename
Saves the editor buffer under the new name, and records it so that
"SAVE" without a file name saves under that file name.
EDIT
Edit the editor buffer. Press function key 'F1' to excape from the
editor
LIST
List the contents of the editor buffer on the screen. Pressthe Right
Mouse Button to temporarily stop the listing, and release it to
allow the listing to continue.
LLIST
Same as LIST, but the contents of the editor buffer are printed
on the printer attached to your Amiga, followed by a Page-Eject.
FILES
Same as the AmigaBASIC "FILES" command. Lists the files in the
current directory on the screen. Requires that the "DIR" command be
in the "C:" directory.
QUIT
Leave logo and return to the operating system.
EDITOR COMMANDS
Use the cursor keys to move up, down, left, and right.
Shift up-cursor moves the cursor up 10 lines.
Shift down-cursor moves the cursor down 10 lines.
Shift left-cursor move the cursor to the beginning of the line.
Shift right-cursor moves the cursor to the end of the line.
The grey DEL key deletes the character under the cursor.
The BACKSPACE key deletes the character just before the cursor.
Shift DEL key deletes an entire line.
Press RETURN to get a new line, or make a line into two lines. Sorry,
no way to join two lines together as yet.
CTRL-Q, CTRL-X and F1 exits from the editor.
EXPRESSIONS
An element can be any of the following:
a. A signed integer number (32 bits). (-235, 447)
b. A built-in variable. (XCOR, YCOR, HEADING, and PENCOLOR.)
c. A procedure call. See the ALOGO command "OUTPUT" on how to
make a procedure return a value. (COORD, FAC 4, DDT 77+2 99.)
d. A user defined variable. These start with a ":", followed by
a letter, and then followed by an optional sequence of letters
and digits. (:a , :a1e2b4, :zzz).
(As in the rest of ALOGO, it does not matter if the letters are
in upper or lower case. Thus, xcor, XCOR, and XcOr are all the same.)
An expression is an element or an algebraic expression using elements.
The following are valid expressions:
5
:a+5
3*(:a-7)
:z/-9+ fac 6 (Procedure call of fac 6. Result is added to :z/-9)
:Q % 6 (Remainder of :Q divided by 6)
-:r (Negative of the value of :r)
xpos+4 (The value of built-in variable xpos has 4
added to it)
The following are valid operators to use in an expression. They
all behave the same as they do in AmigaBASIC.
< - Less than, for comparing two numbers.
= - Equal to, for comparing two numbers.
> - Greater than, for comparing two numbers.
AND - Logical AND.
OR - Logical OR.
NOT - Logical NOT.
* - Multiplication
/ - Division
% - Modulo. Same as MOD in AmigaBASIC.
+ - Addition
- - Subtraction and negation.
The precedence is as follows (same as for BASIC)
()'s (To change the order of the precedence)
- (Negation.)
* , / , % (Same precedence. Done left to right. So 2*3*5/6 is
(((2*3)*5)/6). )
+ , - (Same precedence. Also done left to right.)
<,=,> (Note: <=,=>, and <> are NOT permitted.)
NOT
AND (Done left to right.)
OR (Done left to right.)
Remember that ALOGO does not use anything to separate different
expressions. This can cause problems when using negation.
As an example, if it is desired to print out 1 and -1 on the
same line, the following command will NOT work:
PRINT [1 -1]
It will print out 0, since 1-1 is 0. To get 1 and -1 to be printed
out separately, one must use:
PRINT [1 (-1)]
ALOGO BUILT-IN VARIABLES
The following are the ALOGO built-in variables. They hold the values
of different aspects of the drawing pen.
XCOR
Holds the horizontal coordinate of the pen. It will normally range
from 0 to 610 in value. 0 is for the far left of the window, and
610 is for the far right of the window.
YCOR
Holds the vertical coordinate of the pen. It will normally range
from 0 to 182 in value, 0 is for the top of the window, and 182 is
for the bottom of the window.
HEADING
Holds the heading of the pen, which is the direction in which the
pen will move if given a FORWARD or BACK command. It will range in
value from 0 to 359.
PENCOLOR
Holds the present drawing color of the pen. This will be a value
from 0 to 3. The exact color drawn will depend on the colors set in
the preferences menu.
ALOGO COMMENTS
All ALOGO comments start with a ';', and continue to the end of the
line, and can appear in any line. For example:
CS PD FD 10 ; this will not be executed >> LT 90 FD 10
will draw a line 10 steps long, but will not add the second line going
to the left at the end of the first line.
ALOGO COMMANDS
The following commands can be typed in at the '>' prompt. More
than one command can be typed in on the same line. To stop execution
of the commands or any procedures, press a key on the Amiga keyboard.
The words 'exp', 'exp1', 'exp2', and 'exp3' represent valid expressions
as outlined above. If none of these appear in the command, then the
command does not take any parameters.
Some of the commands can take a 2 letter abbreviation. They can also
be typed in in any mix of upper and lower case letters.
CS
CLEARSCREEN
Clear the screen, put the drawing pen at the center of the screen,
and set the direction to 0 degrees (up). The pen is left up or down.
HOME
Put the drawing pen at the center of the screen and set the direction
to 0 degrees (up). The pen is left either up or down.
CLEAN
Just clear the screen, without affecting the pen location or whether
the pen is up or down.
PU
PENUP
Reset the pen so that the pen will not draw lines when moved.
PD
PENDOWN
Set the Pen so that if the pen is moved, lines will be drawn.
SETPC exp
Set the pen color to the value of (exp % 4). Pen colors are dependent
on the Preferences settings, but they will map to the following colors
on all screens:
0 - Background color.
1 - Color of the letters and the border.
2 - Color of the Depth Arranger gadget in the upper
right corner of the window.
3 - Color of the cursor.
SETPOS [exp1 exp2]
Set the pen to be at horizontal coordinate exp1, and vertical coordinate
exp2. (0,0) is at the upper left corner of the outside of the window, and
(610,182) is at the lower right corner of the window. If the pen is
down, a line is drawn from the previous position to the new position.
THE "[]"'S AROUND THE TWO EXPRESSIONS ARE MANDATORY.
DOT [exp1 exp2]
Places a dot of the present pen color at horizontal coordinate exp1
and vertical coordinate exp2. Exp1 can range from 0 to 610, and exp2
can range from 0 to 182. THE "[]"'s AROUND THE
TWO EXPRESSIONS ARE MANDATORY.
SETX exp
Like SETPOS, but sets the horizontal coordinate only, leaving the
vertical coordinate alone. If the pen is down, then a line is drawn to
the new position from the old position.
SETY exp
Like SETPOS and SETX, but sets the vertical coordinate only, leaving
the horizontal coordinate alone. If the pen is down, then a line is drawn
to the new position from the old position.
FD exp
FORWARD exp
Move in the direction of the heading of the pen (exp) many 'steps'.
(There are 182 steps vertically and 304 horizontally.) If the pen
is down draw a line. Note from SETPOS that a step in the horizontal
direction is doubled. This makes the aspect ratio close to 1:1, so
that the logo statements "FD 10 LT 90 FD 10 LT 90 FD 10 LT 90 FD 10"
forms more of a square than a rectangle.
BK exp
BACK exp
Move in the opposite direction of the heading of the pen (exp)
many 'steps'. BK exp is the same as FD -(exp).
LT exp
LEFT exp
Turn the heading of the pen's heading left (exp) degrees. Directions
on the screen are:
left right
<--- --->
0
^
|
270 <-+-> 90
|
V
180
<--- --->
right left
RT exp
RIGHT exp
Turn the heading of the pen's heading right (exp) degrees. See the
entry for LT and LEFT. RT exp is the same as LT -(exp)
SETH exp
SETHEADING
Turn the heading of the pen to the heading of (exp) degrees. See the
entry for LT and LEFT to see the directions to which the heading will
translate.
PRINT [ {exp | 'string'} {exp | 'string'} . . . ]
Print the strings or the values of the expressions between the
'[' and the ']'. There can be as many expressions or as many strings,
in any order, as you wish between the '[' and the ']'. Strings
*MUST* be surrounded by "'"'s. The following lines print out
various values. The results are shown.
PRINT [ 45*7 ' is 315']
result:315 is 315
PRINT ['this' ' is ' 'a' 'test']
result:this is atest (put 'a ', rather than 'a', to
avoid this.)
print [1*2 2*2 2*4]
result:2 4 8
PRINT [1*2 '+' 2*3 '=' 2*4]
result:2 +6 =8
MAKE "var exp
Changes the value of the procedure variable to be the same as exp.
Thus, if the value of :xxt is 17, then executing:
MAKE "xxt :xxt+5
will change the value of :xxt to 22. Note that the ":" is replaced
by a double quote, which is required. The values of built-in variables
cannot be changed using MAKE.
ALOGO CONTROL STATEMENTS
The following statements affect the flow of control of the program.
Only TO and END can be used in an editor buffer. All the others can be
typed in directly at the '>' prompt, and in the editor buffer.
RP exp [stmt stmt ....]
REPEAT exp [stmt stmt ....]
Repeat all the statements between the '[' and the ']' (exp) times.
If exp is less than or equal to 0, the statements between the '[]''s
are not executed. The following two lines draw the same squares.
CS PD FD 40 LT 90 FD 40 LT 90 FD 40 LT 90 FD 40 LT 90
CS PD REPEAT 4 [FD 40 LT 90]
THE "[]"'s ARE REQUIRED.
IF exp [true statements] [false statements]
IF exp [true statements]
Tests the value of exp, and if true (not zero) all the statements
between the first set of "[]"'s will be true. If a second set of
statements are between "[]"'s and are after the first set, they are
skipped. If the value of exp is false (zero), then the first set
of statements between the "[]"'s is skipped, and the second set of
statements between the second pair of "[]"'s is executed. If a second
set of statements does not exist (as in the second IF statement), then
there is no error. There IS an error if the "[]"'s are missing, or
if there is no first set of statements.
TO procedurename :variable :variable ....
.
.
END
Define a procedure named procedurename, with the variables after it
as parameters. Procedures cannot be defined directly, but must be typed
into the editor buffer.
TO *MUST* be at the beginning of the line, but END does not have to be on
it's own line. Failure to do so will cause ALOGO to complain that a
procedure has not been defined.
When the procedurename and parameters are typed in (using the same syntax
as all the built-in commandss), all the statements between the TO and the
END will be executed.
ALOGO variables begin with a ':' followed by a letter, and can be
composed of letters and digits. ALOGO will not distinguish between
upper and lower case letters, either in the procedure name or the
variable names.
Examples:
((these are typed into the editor buffer))
to square :x ;draw a square :x units on a side.
FD :x LT 90 FD :x LT 90 FD :x LT 90 FD :x LT 90
end
to multisquare :x1 :turn :x ;draw :x squares :x1 units on a side
;turning :turn degrees between each
;drawn square.
RP :x [square :x1 LT :turn] ; this :x will not be confused with
; the :x in square. They are
; different variables.
end
((these are typed in at the '>' prompt))
>square 50 ;draws a square 50 units on a side
>multisquare 30 10 36 ;draws 36 squares that are 30 units on a side
;turning 10 degrees between each square
Trying to execute a procedure that is not defined in the editor buffer
will cause ALOGO to complain.
ALOGO procedures are like AmigaBASIC subroutines, and do not normally
return a value. To make a procedure return a value, so that it can be
used in an expression, see the "OUTPUT" statement.
ALOGO procedures can call other procedures, and can even call
themselves.
OUTPUT exp
To make a procedure return a value, use the OUTPUT statement. The
value returned will be the value of exp. Some examples are:
((The following lines are typed into the Editor Buffer))
to sum3 :x :y :z ;return the sum of :x, :y, :z
output :x+:y+:z
end
((the following lines are typed at the ">" prompt.))
>print [5*sum3 1 2 3] ;do 5*(1+2+3)
30
>print [sum3 1 2 3] ;do 1+2+3
6
The OUTPUT statement can be used anywhere, even in a set of statements
between "[]"'s in the IF and REPEAT statements. The execution of the
IF or the REPEAT will be terminated, and the value returned to the
procedure that called the procedure. It is sort of like the AmigaBASIC
RETURN statement.
STOP
Like the OUTPUT statement, the STOP statement stops the execution
of a procedure and returns to the procedure that called the original
procedure. It is exactly like the AmigaBASIC RETURN statement.
HALT
This is like the AmigaBASIC STOP statement. It stops the execution
of all procedures and returns to the ">" prompt. Pressing a key on
the Amiga keyboard will have the same effect.
FINAL NOTES
ALOGO V1.0 is written entirely in assembly language, which
accounts partly for its speed and partly for its rough edges, since
most of the programming examples provided by Commodore are oriented
towards "C". The headers of the procedures are partly compiled into
a table for quick lookup, and are tied directly to the source code
in the editor. Changing a line in the editor forces this table to
be recompiled. I could have compiled all the procedures in the
editor buffer in their entirety, but there would have been no direct
connection between errors in the compiled code and where the error
was located in the source. Thus, in a child-oriented language, I opted
for making the location of errors easy to do.